package com.SMS;

import com.essential.R;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MMSSendActivity extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.sms);
		btnSend = (Button) findViewById(R.id.btnSend);
		edtPhoneNo = (EditText) findViewById(R.id.edtPhoneNo);
		edtContent = (EditText) findViewById(R.id.edtContent);

		btnSend.setOnClickListener(new View.OnClickListener() {
			private boolean isMMS = true;

			public void onClick(View arg0) {
				String phoneNo = edtPhoneNo.getText().toString();
				String message = edtContent.getText().toString();
				if (phoneNo.length() > 0 && message.length() > 0) {
					if (isMMS) {
						Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
								Uri.parse("sms:"
										+ edtPhoneNo.getText().toString()));
						smsIntent.putExtra("sms_body", edtContent.getText()
								.toString());
						MMSSendActivity.this.startActivity(smsIntent);
					} else {
						Uri attached_Uri = Uri
								.parse("content://media/external/images/media/1");
						Intent mmsIntent = new Intent(Intent.ACTION_SEND,
								attached_Uri);
						mmsIntent.putExtra("sms_body", edtContent.getText()
								.toString());
						mmsIntent.putExtra("address", edtPhoneNo.getText()
								.toString());
						mmsIntent.putExtra(Intent.EXTRA_STREAM, attached_Uri);
						mmsIntent.setType("image/png");
						startActivity(mmsIntent);
					}
				} else {
					Toast.makeText(getBaseContext(),
							"Please enter both phone number and message.",
							Toast.LENGTH_SHORT).show();
				}
			}
		});
	}

	private Button btnSend;
	private EditText edtPhoneNo;
	private EditText edtContent;
}
